import { createStore, applyMiddleware } from "redux";
import reducer from "../reducer";
import asyncMiddleware from "../middleware/myAsyncMiddleware"

// redux-saga 的使用
import createSagaMidddleware from 'redux-saga';
import pageSaga from '../sagas/page.saga';



// 1、基本使用
// 1.1、初始状态
const initalState = {
    name: "王五",
    age: 28,
    users: []
}

// 1.2、创建 store，注册中间件
// export const store = createStore(reducer, initalState, applyMiddleware(asyncMiddleware));





// 2、redux-saga 的使用
// 2.1、创建 sagaMiddleware
const sagaMiddleware = createSagaMidddleware();

// 2.2、注册 sagaMiddleware
export const store = createStore(reducer, initalState, applyMiddleware(sagaMiddleware));

// 2.3、多个中间件同时使用
// const middleware = [asyncMiddleware, sagaMiddleware]
// export const store = createStore(reducer, initalState, applyMiddleware(...middleware));

// 2.4、启动 rootSaga
sagaMiddleware.run(pageSaga)
